package com.docted.design.pattern.proxy.dynamic.jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author DoCted
 * @since v1.0 2018/3/11
 */
public class HouseAgent implements InvocationHandler {


    /**
     * 被代理的对象
     */
    private Graduate target;


    public Object getInstance(Graduate target) {
        this.target = target;
        Class<?> clazz = target.getClass();
        return Proxy.newProxyInstance(clazz.getClassLoader(), clazz.getInterfaces(), this);
    }




    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        System.out.println("I am a House Agent.");
        System.out.println("I got your reference. Let me know what you want.");
        method.invoke(this.target, args);
        System.out.println("Ok. No problem.");
        return null;
    }
}
